<template>
    <el-form :model="form" label-width="40" label-position="left" @submit.prevent>
        <!-- <div class="mb-10 fw">内容设置</div> -->
        <el-form-item label-width="0">
            <div class="flex-col gap-10 w h">
                <div class="new_title flex-row align-c jc-sb"><div class="flex-row">FROM名称<span class="required">*</span></div><div class="new_desc">上传{{ name }}</div></div>
                <form-name :value="all_form_value.form_name" :model-id="all_form_value.id" :is-subform="isSubform" :subform-list="subformList" @name_change="name_change"></form-name>
            </div>
        </el-form-item>
        <el-form-item label-width="0">
            <div class="flex-col gap-10 w h">
                <div class="new_title flex-row align-c jc-sb"><div class="flex-row">标题<span class="required">*</span></div></div>
                <el-input v-model="form.title" placeholder="请输入标题" @change="title_change"></el-input>
            </div>
        </el-form-item>
        <el-form-item label-width="0">
            <div class="flex-col w h">
                <div class="new_title mb-10">校验</div>
                <div><el-checkbox v-model="form.is_required" label="必填" true-value="1" false-value="0" /></div>
                <div class="flex-col gap-10">
                    <div><el-checkbox v-model="form.is_limit_num" :label="`最多${name}数`" true-value="1" false-value="0" /></div>
                    <div v-if="form.is_limit_num == '1'" class="flex-row gap-10"><input-number v-model="form.limit" :min="1" :max="100" /><span class="desc-title">{{ props.acceptType == 'img' ? '张' : '个' }}</span></div>
                </div>
                <div class="flex-col gap-10">
                    <div><el-checkbox v-model="form.is_limit_size" :label="`设置单个${name}大小上限`" true-value="1" false-value="0" /></div>
                    <div v-if="form.is_limit_size == '1'" class="flex-row gap-10"><input-number v-model="form.upload_size" :min="1" :max="1000" /><span class="desc-title">MB</span></div>
                </div>
            </div>
        </el-form-item>
        <border-config class="mb-18" :value="form.common_config" />
        <help-config class="mb-18" :value="form.common_config" />
        <div v-if="!['img', 'video'].includes(props.acceptType)" class="new_tips">上传文件只支持PC,H5,微信小程序,QQ小程序, 不支持的平台会直接隐藏</div>
        <template v-if="isSubform">
            <subform-width v-model="form.com_width"></subform-width>
        </template>
    </el-form>
</template>
<script setup lang="ts">
import { commonStore } from '@/store';
import { cloneDeep, isEmpty } from 'lodash';
const common_store = commonStore();
const props = defineProps({
    value: {
        type: Object,
        default: () => ({}),
    },
    acceptType: {
        type: String,
        default: 'img',
    },
    isSubform: {
        type: Boolean,
        default: false,
    },
    subformList: {
        type: Array,
        default: () => ([]),
    },
    allValue: {
        type: Object,
        default: () => {},
    }
});
const all_form_value = ref(props.allValue);
const form = ref(props.value);// 判断配置项是否有误
//#region 标题更新时的修改
const old_title = ref(cloneDeep(form.value.title));
const title_change = () => {
    if (isEmpty(form.value.title)) {
        form.value.title = old_title.value;
    }
};
//#endregion
const name = computed(() => props.acceptType == 'img' ? '图片' : props.acceptType == 'video' ? '视频' : '文件');
const name_change = (val: string) => {
    all_form_value.value.form_name = val;
}
const emit = defineEmits(['operation_end']);
const operation_end = () => {
    emit('operation_end');
};
</script>

<style scoped lang="scss">
.new_tips {
    color: $cr-error;
    font-size: 1rem;
}
</style>
